import {
  Controller,
  Get,
  Post,
  Body,
  Patch,
  Param,
  Delete,
  Req,
} from '@nestjs/common';
import { CartService } from '../service/cart.service';
import { CreateCartDto } from '../dto/cart/create-cart';
import { UpdateCartDto } from '../dto/cart/update-cart';

@Controller('cart')
export class CartController {
  constructor(private readonly cartService: CartService) {}

  @Post()
  create(@Body() createCartDto: CreateCartDto, @Req() req) {
    return this.cartService.create(createCartDto, req.uesr.userId);
  }

  @Get()
  findAll(@Req() req, pageDto: { pageNo: number; pageSize: number }) {
    return this.cartService.findAll(req.user.userId, pageDto);
  }

  @Get(':id')
  findOne(@Param('id') id: string) {
    return this.cartService.findOne(+id);
  }

  @Patch(':id')
  update(@Req() req, @Param('id') id: string, @Body() updateCartDto: UpdateCartDto) {
    return this.cartService.update(req.user.userId, +id, updateCartDto);
  }

  @Delete(':id')
  remove(@Param('id') id: string) {
    return this.cartService.remove(+id);
  }
}
